/*
 * Epoller.h
 *
 *  Created on: 2009-3-16
 *      Author: gzh
 */

#ifndef EPOLLER_H_
#define EPOLLER_H_

#define	MAX_EPOLL_FD		1024

#include <sys/epoll.h>
#include <unistd.h>
#include <map>

#include "EpollHandler.h"
#include "EpollTypes.h"

using namespace std;
class EpollHandler;			//相互引用

typedef	map<fd_t, EpollHandler*>  HandlerMap;

class Epoller {
public:
	//获得单件实例获得单件实例获得单件实例
	static Epoller & GetInstace();

	virtual void RegisterHandler(EpollHandler &handler,EventType et);

	virtual void UnRegisterHandler(EpollHandler &handler,EventType et);
	//事件轮询
	virtual void StartUp(Time_Value timeout=0);

	void AddEvent(uint32_t event){
		m_events |= event;
	}
	void RemoveEvent(uint32_t event){
		m_events &= ~event;
	}

	virtual ~Epoller(){
		delete inst_;
		close(epfd_);
	}
	//获得epoll专用句柄
	int GetEpfd() const;
private:
	int epfd_;
	uint32_t	m_events;
	static Epoller * inst_;

	Epoller();

	void SetEpfd(int epfd){
		epfd_= epfd;
	}

	//对象指针数组：记录注册到epoller上的处理器对象
//	EpollHandler* handler_[MAX_EPOLL_FD];
	HandlerMap handler_;
};





#endif /* EPOLLER_H_ */
